<script setup lang="ts">
import { storeToRefs } from 'pinia'
import { reactive, watch, computed } from 'vue'
import BarOrLine from '@/components/Echart/Bar/BarOrLine.vue'
import { useFinanceStore } from '@/stores/module/finance'
import { useDialogStore } from '@/stores/dialog'
const dialogStore = useDialogStore()
const { dialogInfo } = dialogStore
const dialogInfoVisible = dialogInfo.visible
const financeStore = useFinanceStore() // 创建store实例
const { getMarginalAmoutRate }: any = storeToRefs(financeStore)

const options = computed(() => {
  return {
    name: 'GetMarginalAmoutRate',

    xAxis: {
      type: 'category',
      data: getMarginalAmoutRate.value.sub_titles,
    },
    data: getMarginalAmoutRate.value.info,
  }
})
watch(
  () => getMarginalAmoutRate.value,
  () => {
    options.value.data.splice(
      0,
      options.value.data.length,
      ...getMarginalAmoutRate.value.info
    )
    options.value.xAxis.data.splice(
      0,
      options.value.xAxis.data.length,
      ...getMarginalAmoutRate.value.sub_titles
    )
  },
  { deep: true }
)
</script>
<template>
  <card-box componentName="GetMarginalAmoutRate">
    <template v-slot:title v-if="getMarginalAmoutRate.title">
      <h1
        :class="{
          subtitle: dialogInfoVisible,
        }"
      >
        {{ getMarginalAmoutRate.title }}
      </h1>
    </template>
    <BarOrLine :chart-data="options" v-if="getMarginalAmoutRate.info.length" />
    <div v-else class="default-img">
      <p>{{ $t('bi_common_nodata') }}</p>
    </div>
  </card-box>
</template>
<style lang="scss" scoped>
.default-img {
  width: 100%;
  text-align: center;
  padding: 120px 0;
  background-image: url('@/assets/images/canvsimage/default.png');
  background-repeat: no-repeat;
  background-position: center;

  font-size: 16px;
  color: #00f6ff;
}
.subtitle {
  font-size: 30px;
}
</style>
